package com.ssps.back.platform.service.Impl;

import com.google.inject.internal.util.$Lists;
import com.ssps.back.platform.service.CommentService;
import com.ssps.entity.Comment;
import com.ssps.entity.CommentExample;
import com.ssps.entity.Parking;
import com.ssps.entity.ParkingExample;
import com.ssps.mapper.CommentMapper;
import com.ssps.mapper.ParkingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * @author li
 * @time 2020/07/23 17:28:05
 */

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentMapper commentMapper;
    @Autowired
    ParkingMapper parkingMapper;
    @Override
    public List<Comment> commentFindAll(String status,String pnumber) {

        CommentExample example=new CommentExample();
        CommentExample.Criteria criteria = example.createCriteria();
        if (status!=""&&status!=null){
            criteria.andStatusEqualTo(status);
        }
        List<Integer> pids=new ArrayList<>();
        if (pnumber!=""&&pnumber!=null){
            ParkingExample parkingExample=new ParkingExample();
            ParkingExample.Criteria parkingExampleCriteria = parkingExample.createCriteria();
            parkingExampleCriteria.andPnumberLike("%"+pnumber+"%");
            List<Parking>parkingList=parkingMapper.selectByExample(parkingExample);
            if (parkingList!=null){
                for (Parking parking : parkingList) {
                    pids.add(parking.getPid());
                }
                criteria.andPidIn(pids);
            }
        }
        List<Comment> commentList=commentMapper.selectByExample(example);
        Parking parking=new Parking();
        if (commentList.size()>0) {
            for (Comment comment : commentList) {
                 parking=parkingMapper.selectByPrimaryKey(comment.getPid());
                 comment.setParking(parking);
            }
        }
        return commentList;
    }

    @Override
    public void commentUpdate(Comment comment) {
        commentMapper.updateByPrimaryKeySelective(comment);
    }
}
